package com.itheima.service.store.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.store.OrdersDao;
import com.itheima.domain.store.Orders;
import com.itheima.factory.DaoInstanceFactory;
import com.itheima.service.store.OrdersService;

import java.util.List;

public class OrdersServiceImpl implements OrdersService {
    @Override
    public void save(Orders orders) {
        OrdersDao ordersDao = DaoInstanceFactory.getMapper(OrdersDao.class);
        ordersDao.save(orders);
    }

    @Override
    public void delete(String id) {
        OrdersDao ordersDao = DaoInstanceFactory.getMapper(OrdersDao.class);
        ordersDao.deleteById(id);
    }

    @Override
    public void update(Orders orders) {
        OrdersDao orderDao = DaoInstanceFactory.getMapper(OrdersDao.class);
        orderDao.update(orders);
    }

    @Override
    public Orders findById(String id) {
        OrdersDao ordersDao = DaoInstanceFactory.getMapper(OrdersDao.class);
        return ordersDao.findById(id);
    }

    @Override
    public List<Orders> findAll() {
        OrdersDao ordersDao = DaoInstanceFactory.getMapper(OrdersDao.class);
        return ordersDao.findAll();
    }

    @Override
    public PageInfo findAll(int page, int size) {
        OrdersDao ordersDao = DaoInstanceFactory.getMapper(OrdersDao.class);
        PageHelper.startPage(page,size);
        List<Orders> list = ordersDao.findAll();
        return new PageInfo(list);
    }
}
